<?php
namespace App\Http\Controllers;

use App\Http\Requests\BasicRequest;
use Illuminate\Http\File;
use Illuminate\Http\Request;
use Illuminate\Support\Facades\Storage;

class UploadController extends CommonController {
	
	/**
	 * 上传图片方法
	 */
	public function image(BasicRequest $request){
		$type = $request->input('type','images');
		$url = base64_upload($type,'image');
		$return = [
			'image_url' => $url,
		];
		return json_return($url,'','图片上传成功',$return);
	}
	
	/**
	 * @param BasicRequest $request
	 * @return string
	 * form 表单上传文件方法
	 */
	public function image_form(BasicRequest $request){
		$type = $request->input('type','images');
		$path = $request->file('image')->store('public/'.$type.'/'.date('Y-m-d'));
		$path = str_replace_first('public','storage',$path);
		$return = [
			'image_url' => 'http://api.'.env('APP_DOMAIN').'/'.$path,
		];
		return json_return($path,'','图片上传成功',$return);
	}
	
	/**
	 * @param BasicRequest $request
	 * @return array
	 * 上传文件方法
	 */
	public function file(BasicRequest $request){
		$type = $request->input('type','files');
		$url = base64_upload($type,'file');
		$return = [
			'file_url' => $url,
		];
		return json_return($url,'','文件上传成功',$return);
	}
}